package test.test_7_6;
/*
"peter piper picked a peck of pickled peppers"
统计这段绕口令有多少个以p开头的单词
提示:借助split(" ")方法分隔成字符串数组 , startsWith("p")判断是否是p开头
 */

public class Demo {
    public static void main(String[] args) {
        String str = "peter piper picked a peck of pickled peppers";
        String[] arr = str.split(" ");
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i]+" ");
//        }

        //计数器
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].startsWith("p")) {
                count++;
            }
        }
        System.out.println(count);
    }
}
